/**
 * Created by lee_mxue on 17/7/31.
 */
import React, {Component, PropTypes} from "react";
import { addErrorListener } from "../../lib/handleError"
import weixinShare from "../../lib/weixinShare";
import AJAX from "../../lib/ajax";
import Tools from "../../lib/tools";

require('../../lib/rem')
require('../../styles/common.less');
require('./PickUpOrderLog.less')
require('../../styles/lux.less')
const IconBlock = require('../MyPackage/components/IconBlock');

class TopUp extends Component {
    constructor(props) {
        super(props);
        this.state = {
            isReady: false,     //是否可以加载页面
            sms_log: [],     //短信信息
            opera_log: [],     //操作信息
            wechat_log: [],     //微信信息
        }
    }

    componentWillMount() {
        addErrorListener()()
        //隐藏分享功能
        weixinShare.hideAll();
        //    获取列表
        this.getList()   
    }

    componentDidMount() {
        AJAX.appendBaiduAnalysis()
        this.setState({
            isReady: true
        })
    }

    //获取列表
    getList() {
        const id = Tools.getParams().order_id;
        AJAX.request("order_log_list", {order_id: id}, (data) => {
            if (data.code === 0) {
                this.setState({
                    sms_log: data.body.sms_log,     //短信信息
                    opera_log: data.body.opera_log,     //操作信息
                    wechat_log: data.body.wechat_log,     //微信信息
                })
            }
        })
    }

    render() {

        return (
            this.state.isReady &&
            <div className="main_box">
                {this.state.opera_log.length > 0
                && <div className="opera_mian_list">
                    <p>操作信息</p>
                    <ul className="borderB">
                        {this.state.opera_log.map(item => {
                            return (
                                <li className="borderT">
                                    <div className="time">{item.time}</div>
                                    <div className="content">
                                        {item.desc}
                                    </div>
                                </li>
                            )
                        })}

                    </ul>
                </div>}

                {this.state.sms_log.length > 0
                && <div className="sms_mian_list">
                    <p>短信信息</p>
                    <ul className="borderB">
                        {this.state.sms_log.map(item => {
                            return (
                                <li className="borderT">
                                    <div className="time">{item.time}</div>
                                    <div className="contentBox flex">
                                        <div className="title">{item.title} :</div>
                                        <div className="content flex1">
                                            {item.desc}
                                        </div>
                                    </div>
                                </li>
                            )
                        })}
                    </ul>
                </div>
                }

                {this.state.wechat_log.length > 0
                && <div className="wechat_mian_list">
                    <p>微信信息</p>
                    <ul className="borderB">
                        {this.state.wechat_log.map(item => {
                            return (
                                <li className="borderT">
                                    <div className="time">{item.time}</div>
                                    <div className="contentBox flex">
                                        <div className="title">{item.title} :</div>
                                        <div className="content flex1">
                                            {item.desc}
                                        </div>
                                    </div>
                                </li>
                            )
                        })}
                    </ul>
                </div>
                }
            </div>
        )
    }
}

ReactDOM
    .render(
        <TopUp />,
        document
            .getElementById(
                'app'
            ))
if (module

        .hot
) {
    module
        .hot
        .accept();
}

